// 模拟用户数据
export const users = [
  {
    username: 'admin',
    password: '123456',
    role: 'admin',
    avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
    token: 'admin-token'
  },
  {
    username: 'user',
    password: '123456',
    role: 'user',
    avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
    token: 'user-token'
  }
]

// 模拟登录接口
export const login = (username, password) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      const user = users.find(
        user => user.username === username && user.password === password
      )
      if (user) {
        resolve({
          code: 200,
          data: {
            token: user.token,
            userInfo: {
              username: user.username,
              role: user.role,
              avatar: user.avatar
            }
          },
          message: '登录成功'
        })
      } else {
        reject({
          code: 401,
          message: '用户名或密码错误'
        })
      }
    }, 1000)
  })
}

// 模拟获取用户信息接口
export const getUserInfo = (token) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      const user = users.find(user => user.token === token)
      if (user) {
        resolve({
          code: 200,
          data: {
            username: user.username,
            role: user.role,
            avatar: user.avatar
          },
          message: '获取用户信息成功'
        })
      } else {
        reject({
          code: 401,
          message: '获取用户信息失败'
        })
      }
    }, 500)
  })
} 